package com.gec.anan.driver.service.impl;

import com.gec.anan.common.execption.AnanException;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.result.ResultCodeEnum;
import com.gec.anan.driver.client.DriverInfoFeignClient;
import com.gec.anan.driver.service.LocationService;
import com.gec.anan.map.client.LocationFeignClient;
import com.gec.anan.map.client.MapFeignClient;
import com.gec.anan.model.entity.driver.DriverSet;
import com.gec.anan.model.form.map.OrderServiceLocationForm;
import com.gec.anan.model.form.map.UpdateDriverLocationForm;
import com.gec.anan.model.form.map.UpdateOrderLocationForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationServiceImpl implements LocationService {
    @Autowired
    private LocationFeignClient locationFeignClient;
    @Autowired
    private DriverInfoFeignClient driverInfoFeignClient;

    //更新司机的位置信息
    @Override
    public Boolean updateDriverLocation(UpdateDriverLocationForm updateDriverLocationForm) {
        Result<DriverSet> driverSetResult = driverInfoFeignClient.getDriverSet(updateDriverLocationForm.getDriverId());
        DriverSet driverSet = driverSetResult.getData();
        //1-可以接单，0-不接单
        if(driverSet!=null&&driverSet.getServiceStatus()==1){
            Result<Boolean> booleanResult = locationFeignClient.updateDriverLocation(updateDriverLocationForm);
            Boolean booleanResultData = booleanResult.getData();
            System.out.println("司机可以接单");
            return booleanResultData;
        }else{
            throw new AnanException(ResultCodeEnum.NO_START_SERVICE);
        }
    }

    @Override
    public Boolean removeDriverLocation(Long driverId) {
        return locationFeignClient.removeDriverLocation(driverId).getData();
    }

    //司机到乘客的最优路线
    @Override
    public Boolean updateOrderLocationToCache(UpdateOrderLocationForm updateOrderLocationForm) {
        return locationFeignClient.updateOrderLocationToCache(updateOrderLocationForm).getData();
    }

    //将位置信息上传到mongodb中
    @Override
    public Boolean saveOrderServiceLocation(List<OrderServiceLocationForm> orderServiceLocationFormList) {
        return locationFeignClient.saveOrderServiceLocation(orderServiceLocationFormList).getData();
    }
}
